import { storeKeyPrefix } from "../../settings";
import { defineStore } from 'pinia'
import { setToken, removeToken } from '@/utils/auth'

export const useUserStore = defineStore(storeKeyPrefix+'__user',{
  state: () => {
    return {
      token: null
    }
  },
  getters:{
    getUserInfo: (state) => () => {
      return state.user;
    },
  },
  actions:{
    setUserInfo(obj){
      this.user = obj
    },
    
    login(obj){
      this.token = obj.token
      setToken(obj.token)
    },
   
    // 退出登录
    logout(){
      this.token = null
      this.user={}
      removeToken()
    }
  },
  persist: {
    storage: localStorage
  }
})